/**
 * @brief 马甲技能工具
 */
import VestUtil from '@//util/unit/VestUtil';
import { OrderId } from "@/w3ts/globals/order";


export default class VestAbilityUtil {

    //  施放沉默技能(指定点)
    static silence(whichUnit: unit, duration: number, range: number = 300, x: number = GetUnitX(whichUnit), y: number = GetUnitY(whichUnit)) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilicode = FourCC('AIse');
        UnitAddAbility(vest, abilicode);
        let ability = EXGetUnitAbility(vest, abilicode);
        IncUnitAbilityLevel(vest, abilicode);
        EXSetAbilityDataReal(ability, 1, 101, 0);           //  魔法施放时间
        EXSetAbilityDataReal(ability, 1, 106, range);       //  影响区域
        EXSetAbilityDataReal(ability, 1, 107, 99999);       //  施法距离
        EXSetAbilityDataReal(ability, 1, 102, duration);    //  持续时间-普通
        EXSetAbilityDataReal(ability, 1, 103, duration);    //  持续时间-英雄
        EXSetAbilityDataInteger(ability, 1, 104, 0);        //  魔法消耗
        DecUnitAbilityLevel(vest, abilicode);
        IssuePointOrderById(vest, OrderId.Silence, x, y);
    }

    //  施放缠绕技能(指定单位)
    static entanglingroots(whichUnit: unit, damage: number, duration: number, targetWidget: widget) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilicode = FourCC('AEer');
        UnitAddAbility(vest, abilicode);
        let ability = EXGetUnitAbility(vest, abilicode);
        IncUnitAbilityLevel(vest, abilicode);
        EXSetAbilityDataReal(ability, 1, 101, 0);           //  魔法施放时间
        EXSetAbilityDataReal(ability, 1, 107, 99999);       //  施法距离
        EXSetAbilityDataReal(ability, 1, 102, duration);    //  持续时间-普通
        EXSetAbilityDataReal(ability, 1, 103, duration);    //  持续时间-英雄
        EXSetAbilityDataReal(ability, 1, 108, damage);      //  每秒伤害
        EXSetAbilityDataInteger(ability, 1, 104, 0);        //  魔法消耗
        DecUnitAbilityLevel(vest, abilicode);
        IssueTargetOrderById(vest, OrderId.Entanglingroots, targetWidget);
    }

    //  施放风暴之锤技能(指定单位)
    static thunderbolt(whichUnit: unit, damage: number, duration: number, targetWidget: widget) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilicode = FourCC('AHtb');
        UnitAddAbility(vest, abilicode);
        let ability = EXGetUnitAbility(vest, abilicode);
        IncUnitAbilityLevel(vest, abilicode);
        EXSetAbilityDataReal(ability, 1, 101, 0);           //  魔法施放时间
        EXSetAbilityDataReal(ability, 1, 107, 99999);       //  施法距离
        EXSetAbilityDataReal(ability, 1, 102, duration);    //  持续时间-普通
        EXSetAbilityDataReal(ability, 1, 103, duration);    //  持续时间-英雄
        EXSetAbilityDataReal(ability, 1, 108, damage);      //  每秒伤害
        EXSetAbilityDataInteger(ability, 1, 104, 0);        //  魔法消耗
        DecUnitAbilityLevel(vest, abilicode);
        IssueTargetOrderById(vest, OrderId.Thunderbolt, targetWidget);
    }

    //  施放减速技能(指定单位)
    static slow(whichUnit: unit, moveSpeed: number, attackSpeed: number, duration: number, targetWidget: widget) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilicode = FourCC('Aslo');
        UnitAddAbility(vest, abilicode);
        let ability = EXGetUnitAbility(vest, abilicode);
        IncUnitAbilityLevel(vest, abilicode);
        EXSetAbilityDataReal(ability, 1, 101, 0);               //  魔法施放时间
        EXSetAbilityDataReal(ability, 1, 107, 99999);           //  施法距离
        EXSetAbilityDataReal(ability, 1, 102, duration);        //  持续时间-普通
        EXSetAbilityDataReal(ability, 1, 103, duration);        //  持续时间-英雄
        EXSetAbilityDataReal(ability, 1, 108, moveSpeed);       //  移动速度减少百分比
        EXSetAbilityDataReal(ability, 1, 109, attackSpeed);     //  攻击速度减少百分比
        EXSetAbilityDataInteger(ability, 1, 104, 0);            //  魔法消耗
        DecUnitAbilityLevel(vest, abilicode);
        IssueTargetOrderById(vest, OrderId.Slow, targetWidget);
    }

    //  施放隐身技能(指定单位)
    static invisibility(whichUnit: unit, duration: number, targetWidget: widget) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilcode = FourCC('Aivs');  //  需要修改科技树限制
        if (GetPlayerTechCountSimple(FourCC('Rhst'), GetOwningPlayer(whichUnit)) < 1) {
            AddPlayerTechResearched(GetOwningPlayer(whichUnit), 'Rhst', 1);
        }
        UnitAddAbility(vest, abilcode);
        SetUnitAbilityLevel(vest, abilcode, 1);
        IncUnitAbilityLevel(vest, abilcode);
        EXSetAbilityDataReal(EXGetUnitAbility(vest, abilcode), 1, 102, duration);
        EXSetAbilityDataReal(EXGetUnitAbility(vest, abilcode), 1, 103, duration);
        DecUnitAbilityLevel(vest, abilcode);
        IssueTargetOrderById(vest, OrderId.Invisibility, targetWidget);
    }

    //  施放咆哮技能(无目标)
    static roar(whichUnit: unit, duration: number, range: number, attackRate: number) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilcode = FourCC('AIrr');
        UnitAddAbility(vest, abilcode);
        let ability = EXGetUnitAbility(vest, abilcode);
        SetUnitAbilityLevel(vest, abilcode, 1);
        IncUnitAbilityLevel(vest, abilcode);
        EXSetAbilityDataReal(EXGetUnitAbility(vest, abilcode), 1, 102, duration);   //  持续时间-普通
        EXSetAbilityDataReal(EXGetUnitAbility(vest, abilcode), 1, 103, duration);   //  持续时间-英雄
        EXSetAbilityDataReal(ability, 1, 106, range);                               //  影响区域
        EXSetAbilityDataReal(ability, 1, 108, attackRate);                          //  攻击力增加百分比
        EXSetAbilityDataInteger(ability, 1, 104, 0);                                //  魔法消耗
        DecUnitAbilityLevel(vest, abilcode);
        IssueImmediateOrderById(vest, OrderId.Roar);
    }

    //  施放精灵之火技能(指定单位)
    static faeriefire(whichUnit: unit, duration: number, defReduce: number, targetWidget: widget) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilicode = FourCC('Afae');
        UnitAddAbility(vest, abilicode);
        let ability = EXGetUnitAbility(vest, abilicode);
        IncUnitAbilityLevel(vest, abilicode);
        EXSetAbilityDataReal(ability, 1, 101, 0);               //  魔法施放时间
        EXSetAbilityDataReal(ability, 1, 107, 99999);           //  施法距离
        EXSetAbilityDataReal(ability, 1, 102, duration);        //  持续时间-普通
        EXSetAbilityDataReal(ability, 1, 103, duration);        //  持续时间-英雄
        EXSetAbilityDataReal(ability, 1, 108, defReduce);       //  护甲减少
        EXSetAbilityDataInteger(ability, 1, 104, 0);            //  魔法消耗
        DecUnitAbilityLevel(vest, abilicode);
        IssueTargetOrderById(vest, OrderId.Faeriefire, targetWidget);
    }

    //  施放飓风技能(指定单位)
    static cyclone(whichUnit: unit, duration: number, targetWidget: widget) {
        let vest = VestUtil.SunCreateVestByUnit(whichUnit, GetUnitX(whichUnit), GetUnitY(whichUnit));
        let abilicode = FourCC('AIcy');
        UnitAddAbility(vest, abilicode);
        let ability = EXGetUnitAbility(vest, abilicode);
        IncUnitAbilityLevel(vest, abilicode);
        EXSetAbilityDataReal(ability, 1, 101, 0);           //  魔法施放时间
        EXSetAbilityDataReal(ability, 1, 107, 99999);       //  施法距离
        EXSetAbilityDataReal(ability, 1, 102, duration);    //  持续时间-普通
        EXSetAbilityDataReal(ability, 1, 103, duration);    //  持续时间-英雄
        EXSetAbilityDataInteger(ability, 1, 104, 0);        //  魔法消耗
        DecUnitAbilityLevel(vest, abilicode);
        IssueTargetOrderById(vest, OrderId.Cyclone, targetWidget);
    }

    //  单位变身
    static unitTransform(whichUnit: unit, abilityId: number, targetId: number) {
        UnitAddAbility(whichUnit, abilityId);
        EXSetAbilityDataInteger(EXGetUnitAbility(whichUnit, abilityId), 1, 117, GetUnitTypeId(whichUnit));
        EXSetAbilityAEmeDataA(EXGetUnitAbility(whichUnit, abilityId), GetUnitTypeId(whichUnit))
        UnitRemoveAbility(whichUnit, abilityId);
        UnitAddAbility(whichUnit, abilityId);
        EXSetAbilityAEmeDataA(EXGetUnitAbility(whichUnit, abilityId), targetId);
        UnitRemoveAbility(whichUnit, abilityId);
    }

}